use std::sync::Arc;

use axum::extract::*;
use axum::Router;
use axum::routing::get;
use serde_json::Value;
use tokio::sync::Mutex;

use crate::app_state::AppState;
use crate::util_entity::anyhow_res::{json_success_response, JsonResult};
pub fn route () -> Router<Arc<Mutex<AppState>>> {
    Router::new()
        .route("/GetCfgList", get(get_config))
        .route("/GetAddr", get(get_addr))
}

pub async fn get_config(State(app_state): State<Arc<Mutex<AppState>>>) -> JsonResult<Value> {
    Ok(json_success_response(app_state.lock().await.machine_config.cfg.clone()))
}

pub async fn get_addr(State(app_state): State<Arc<Mutex<AppState>>>) -> JsonResult<Value> {
    Ok(json_success_response(app_state.lock().await.appsettings.Addr.clone()))
}

